local class = require 'middleclass'
require 'util'

Bullet = class('bullet')
function Bullet:initialize(parent)
    self.parent = parent
    self.speed = 500
    self.rot = self.parent.rot
    self.x = self.parent.x + self.parent.w / 2 * math.sin(self.rot)
    self.y = self.parent.y - self.parent.h / 2 * math.cos(self.rot)
    self.vx = self.speed
    self.vy = -self.speed
    self.img = lg.newImage('assets/bullet.png')
    self.ox = self.img:getWidth() / 2
    self.oy = self.img:getHeight() / 2
end
function Bullet:update(dt, l, r, t, b)
    self.x = self.x + self.vx * math.sin(self.rot) * dt
    self.y = self.y + self.vy * math.cos(self.rot) * dt
    if self.x > r or self.x < l or self.y < t or self.y > b then
        self.destroyed = true
    end
end
function Bullet:draw()
    lg.draw(self.img, self.x, self.y, self.rot, 1, 1, self.ox, self.oy)
end
